package com.cbg.archives.repository;

import com.cbg.archives.entity.EsArchivesModularCol;
import com.cbg.dto.SelectedColListDTO;
import com.shuyuwl.core.repository.DaoRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 档案分类模块展示列 repository
 *
 * @author wangjuzheng
 * @since 2019-10-16
 */
@Repository
public interface IEsArchivesModularColRepository extends DaoRepository<EsArchivesModularCol, Long> {

    /**
     * 根据模块id删除模块对应的列信息
     *
     * @param modularId 模块id
     * @param status    删除状态
     */
    @Modifying
    @Query("update EsArchivesModularCol set status=?2 where modularId=?1")
    void deleteByModularId(Long modularId, Byte status);

    /**
     * 获取选中的列信息
     *
     * @param modularId 模块id
     * @param status    模块的列状态
     * @param colStatus 基础列状态
     * @return 选中的列信息
     */
    @Query(" select new com.cbg.dto.SelectedColListDTO(a.id,a.colId,c.name,c.nameCn,a.colName,a.status) from EsArchivesModularCol a left join EsCol c on a.colId = c.id" +
            " where a.modularId=?1 and a.status<?2 and c.status=?3 ")
    List<SelectedColListDTO> selectedModular(Long modularId, Byte status, Byte colStatus);

    /**
     * 获取列的详情
     *
     * @param id        模块的列id
     * @param status    模块的列状态sd
     * @param colStatus 基础列状态
     * @return 列的详情
     */
    @Query(" select a from EsArchivesModularCol a left join EsCol c on a.colId = c.id" +
            " where a.id=?1 and a.status<?2 and a.status=?3 ")
    EsArchivesModularCol getEsArchivesModularCol(Long id, Byte status, Byte colStatus);
}
